<?php

use yii\helpers\Html;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $searchModel app\models\UsersSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '用户管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="users-index">

    <h1><?php echo Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?php echo Html::a('添加用户', ['create'], ['class' => 'btn btn-success']) ?>
    </p>

    <?php
    echo GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            //['class' => 'yii\grid\SerialColumn'],
            [
                'attribute' => 'id',
                'headerOptions' => ['width' => '100']
            ],
            [
                'attribute' => 'rid',
                'value' => function($model) {
                    if ($model->rid == 1) {
                        $role = '管理员';
                    } elseif ($model->rid == 2) {
                        $role = '注册会员';
                    }
                    return $role;
                },
                'headerOptions' => ['width' => '100']
            ],
            'username',
            'email:email',
            //'password',
            [
                'attribute' => 'prestige',
                'headerOptions' => ['width' => '100']
            ],
            //'avatar',
            [
                'attribute' => 'status',
                'value' => function($model) {
                    return $model->status == 1 ? "开启" : "关闭";
                },
                'headerOptions' => ['width' => '70']
            ],
            [
                'attribute' => 'created_at',
                'label' => '注册时间',
                'value' => function($model) {
                    return date('Y-m-d', $model->created_at);
                },
                'headerOptions' => ['width' => '100']
            ],
            // 'updated_at',
            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]);
    ?>

</div>
